
/* GENERATED CODE:
 *  Any modifications you make are guaranteed
 *  to be deleted when this is regenerated.
 * Please edit "PROTOCOLS" inside this directory
 *
 * Names are all upper case because of "String" and "string."
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using OWED.Network.Messages.General;
using OWED.Network.Messages;
using OWED.Network.Messages.Reply;


namespace OWED.Network.Messages
{
	public class GetDocument: IProtocolItem 
	{
		User my_user;
		DocName my_docname;
		DocVersion my_docversion;
		public GetDocument (User user, DocName docname, DocVersion docversion)
		{
			my_user = user;
			my_docname = docname;
			my_docversion = docversion;
		}
		public GetDocument (User user, DocName docname)
		{
			my_user = user;
			my_docname = docname;
		}
		public User User { get { return my_user; } }
		public DocName DocName { get { return my_docname; } }
		public DocVersion DocVersion { get { return my_docversion; } }


		public static new GetDocument FromXml(XmlDocument xml)
		{
			XmlDocument doc;
			if (xml.SelectSingleNode("GetDocument/User") != null &&
					xml.SelectSingleNode("GetDocument/DocName") != null &&
					xml.SelectSingleNode("GetDocument/DocVersion") != null) {
				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("GetDocument/User"), true));
				User user = User.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("GetDocument/DocName"), true));
				DocName docname = DocName.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("GetDocument/DocVersion"), true));
				DocVersion docversion = DocVersion.FromXml(doc);

				return new GetDocument(user, docname, docversion);
			}
			if (xml.SelectSingleNode("GetDocument/User") != null &&
					xml.SelectSingleNode("GetDocument/DocName") != null) {
				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("GetDocument/User"), true));
				User user = User.FromXml(doc);

				doc = new XmlDocument();
				doc.AppendChild(doc.ImportNode(xml.SelectSingleNode("GetDocument/DocName"), true));
				DocName docname = DocName.FromXml(doc);

				return new GetDocument(user, docname);
			}
			throw new ConnectionException("Bad document supposedly of type:GetDocument");
		}


		public override XmlDocument ToXml()		{
			XmlDocument doc = new XmlDocument();

			doc.AppendChild(doc.CreateElement("GetDocument"));

			if (my_user != null) {
				XmlNode node;
				node = doc.ImportNode(my_user.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_docname != null) {
				XmlNode node;
				node = doc.ImportNode(my_docname.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_docname != null) {
				XmlNode node;
				node = doc.ImportNode(my_docname.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_docversion != null) {
				XmlNode node;
				node = doc.ImportNode(my_docversion.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			if (my_user != null) {
				XmlNode node;
				node = doc.ImportNode(my_user.ToXml().FirstChild, true);
				doc.FirstChild.AppendChild(node);
			}

			return doc;
		}
	}
}
